package com.xuecheng.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xuecheng.po.CourseTeacher;
import com.xuecheng.service.CourseTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 课程教师关系接口
 */
@Slf4j
@RestController("CourseTeacherController")
@RequestMapping("/courseTeacher")
@Api(value = "课程教师关系表", tags = "课程教师接口")
public class CourseTeacherController {
	
	@Resource
	private CourseTeacherService courseTeacherService;
	
	/**
	 * 查询教师信息
	 */
	@GetMapping("/list/{id}")
	public List<CourseTeacher> getCourseTeacherById(@PathVariable Long id) {
		log.info("查询教师信息id：{}", id);
		return courseTeacherService.list(Wrappers.<CourseTeacher>lambdaQuery().eq(CourseTeacher::getCourseId, id));
	}
	
	/**
	 * 添加教师信息
	 */
	@PostMapping
	public CourseTeacher addCourseTeacher(@RequestBody CourseTeacher courseTeacher) {
		return courseTeacherService.addCourseTeacher(courseTeacher);
	}
	
	/**
	 * 修改教师信息
	 */
	@PutMapping
	@ApiOperation("修改教师信息")
	public CourseTeacher updateCourseTeacher(@RequestBody CourseTeacher courseTeacher) {
		log.info("修改教师信息：{}", courseTeacher);
		return courseTeacherService.updateCourseTeacher(courseTeacher);
	}
	
	/**
	 * 删除教师信息
	 */
	@DeleteMapping("/{courseId}/{id}")
	public void deleteCourseTeacher(@PathVariable Long courseId, @PathVariable Long id) {
		log.info("删除课程教师信息courseId：{}，id：{}", courseId, id);
		courseTeacherService.remove(Wrappers.<CourseTeacher>lambdaQuery().eq(CourseTeacher::getCourseId, courseId).eq(CourseTeacher::getId, id));
	}
}
